3259. Divisors

 

Find the smallest possible integer x, that has exactly n divisors.

 

Input. One positive integer n (1 ≤ n ≤ 16).

 

Output. Print the smallest possible integer x that has exactly n divisors.

 

Sample input 1

Sample output 1

2

2

 

 

Sample input 2

Sample output 2

4

6

 

 

SOLUTION

number theory - divisors

 

Algorithm analysis

Iterate through the numbers x = 1, 2, 3, ... and print the first one, which contains exactly n divisors. This solution will pass time limit, since n is not big.

 

Algorithm realization

The function Divisors counts the number of divisors in the number n using a simple full search.

 

int Divisors(int n)

{

  int res = 0, i;

  for(i = 1; i <= n; i++)

    if (n % i == 0) res++;

  return res;

}

 

The main part of the program. Read the value of n.

 

scanf("%d",&n);

 

Iterate over the numbers i = 1, 2, 3, … . Stop the loop as soon as the number i contains n divisors.

 

for(i = 1; ; i++)

{

  d = Divisors(i);

  if (d == n) break;

}

 

Print the answer.

 

printf("%d\n",i);